package io.yizoo.business.controller;

import io.elm.core.CoreController;
import io.yizoo.business.entity.*;
import org.springframework.web.bind.annotation.*;

import java.util.*;


@RestController
@RequestMapping("/business/hrm/daily")
public class hrm_dailyController extends CoreController {

    @Override
    protected void Init() {
        PowerEntity = biz_hrm_daily.class;
        PowerUse = EnumSet.of(Power.IDDelete, Power.IDAny, Power.IDGetSingle,Power.IDUpsert);
    }

    @PostMapping("/GetData")
    public Object GetData(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("t.*,ifnull(a.name,t.create_user) as create_user_mc,ifnull(b.name,t.pj_code) as pj_mc")
                        .From(biz_hrm_daily.class,"t")
                        .LeftJoin(biz_hrm_ei_basic.class,"a","a.emp_code=t.create_user")
                        .LeftJoin(biz_pmis_pj.class,"b","b.sys_code_key=t.pj_code")
                        .IsWhere("and t.create_date = #{date}", "date")
                        .OrderBy("t.create_date desc")
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(ret);
    }

    @PostMapping("/GetTaskData")
    public Object GetTaskData(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("t.assignee_id as create_user,b.sys_code_key as pj_code,t.remark,t.name as work,ifnull(a.name,t.assignee_id) as create_user_mc,ifnull(b.name,t.pj_id) as pj_mc")
                        .From(biz_pmis_pj_task.class,"t")
                        .LeftJoin(biz_hrm_ei_basic.class,"a","a.emp_code=t.assignee_id")
                        .LeftJoin(biz_pmis_pj.class,"b","b.id=t.pj_id")
                        .IsWhere("and (#{date} BETWEEN t.jh_start_time and t.jh_end_time or #{date} BETWEEN t.sj_start_time and t.sj_end_time)", "date")
                        .OrderBy("t.jh_end_time desc")
                        .GetFactor());
        return JsonResult(ret);
    }

    @PostMapping("/GetRwzpData")
    public Object GetRwzpData(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("t.to_person as create_user,t.remark,t.content as work,ifnull(a.name,t.to_person) as create_user_mc")
                        .From(biz_pmis_rwzp.class,"t")
                        .LeftJoin(biz_hrm_ei_basic.class,"a","a.emp_code=t.to_person")
                        .IsWhere("and (#{date} BETWEEN t.start_time and t.jh_end_time or #{date} BETWEEN t.start_time and t.sj_end_time)", "date")
                        .OrderBy("t.jh_end_time desc")
                        .GetFactor());
        return JsonResult(ret);
    }
}
